home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / jdp1_4.zip / JDP1_4.EXE / data.1 / JDPLayout1.java < prev    next >
Text File  |  1996-11-06  |  13KB  |  473 lines

  1. >XXX0455  Total lines for the build status message calculation
  2. //--------------------------------------------------------------------
  3. //                                                                    
  4. >001//  Module:       <JDPModule>                                       
  5. >002//  Description:  <Class Description>
  6. //                                                                    
  7. //--------------------------------------------------------------------
  8.  
  9. import java.awt.*;
  10. import java.applet.*;
  11. import java.util.StringTokenizer;
  12. import java.util.Vector;
  13.  
  14.  
  15. >003public class <JDPUserBill> extends JDPClassLayout {
  16.  
  17.     JDPUser user;
  18.     JDPJagg jaggSQL;
  19.     JDPWhereClause jdpWhereClause;
  20.     JDPSearchResults searchResults;
  21.     JDPPopupMessage popuppanel;
  22.     JDPTabSelectPanel tabPanel;
  23.  
  24.     String[] psortChoice;
  25.     String[] pdisplayChoice;
  26.     int itemIndex;
  27.     boolean insertRequested = false;
  28.     boolean deleteRequested = false;
  29.     String pfromWhereClause;
  30.  
  31.     Vector pmatchUsing;
  32.     Vector pactualmatchUsing;
  33.     //
  34.     //  Declare screen components
  35.     //
  36. >004    <TextField username>;
  37.  
  38.  
  39.     public void InitClass(JDPUser user, Panel targetPanel, String moduleParameter) {
  40.  
  41.         this.user = user;
  42.         //
  43.         //  Set JAGG settings for this class
  44.         //
  45.         jaggSQL = new JDPJagg(user.jaggPath);
  46.         jaggSQL.setNULL("space");
  47. >997        jaggSQL.setMRW("<maxRows>");
  48. >998        jaggSQL.setDSN("<datasource>");
  49. >999        jaggSQL.setCSTR("<connectstr>");
  50.  
  51.         setLayout(new BorderLayout());
  52.         setFont(user.plainFont);
  53.          popuppanel = new JDPPopupMessage(user,targetPanel);
  54.         targetPanel.add(popuppanel);
  55.  
  56.         Panel mainPanel = new Panel();
  57.         mainPanel.setLayout(new BorderLayout());
  58.         Panel centerPanel = new Panel();
  59.         centerPanel.setLayout(new BorderLayout());
  60.         Panel centerMainPanel = new Panel();
  61.         centerMainPanel.setLayout(new BorderLayout());
  62.         Panel leftPanel = new Panel();
  63.         leftPanel.setLayout(new BorderLayout());
  64.         
  65.         //
  66.         //  Define parameters for JDPSearchResults
  67.         //
  68. >005        String pselectFields = "<>"; String[] psdisplayFields = {<>};
  69. >006        pfromWhereClause = "<FROM JDPUser WHERE >";
  70.  
  71. >007        psortChoice = new String[<5>];
  72. >008        psortChoice[<0>] = "<username>";
  73.  
  74. >009        String[] psortChoiceText = {<"Sort by User Name","Sort by Card Number">};
  75.         pdisplayChoice = psortChoice;
  76.  
  77. >010        boolean pdisplayCount = <true>;
  78. >011        String pcountText = "<Total Entries:>";
  79.     
  80.         //
  81.         //  Create an instance of screen components
  82.         //
  83. >012        <username> = new <TextField("",20)>;
  84.  
  85.         //
  86.         //  Initialise any choice components
  87.         //
  88.         loadChoices();
  89.  
  90.         //
  91.         //  Add components to the screen
  92.         //
  93. >058        JDPScrollPanel[] centerTopPanel = new JDPScrollPanel[<>];
  94. >059        centerTopPanel[<>] = new JDPScrollPanel();
  95. >013        centerTopPanel[<>].add("Left",new JDPWrapLabel(user,"<User Name:>",Color.<labelColor>));
  96. >014        centerTopPanel[<>].add("Right",centerR<0>);
  97.  
  98.         if (centerTopPanel.length == 1) {
  99.             centerMainPanel.add("Center",centerTopPanel[0]);
  100.         } else {
  101. >060            String[] titles = {<>};
  102.             tabPanel = new JDPTabSelectPanel(user,titles,centerTopPanel,"North");
  103.             centerMainPanel.add("Center",tabPanel);
  104.         }
  105.         
  106.         // 
  107.         //  Set screen component attributes
  108.         //
  109. >039        <username>.setForeground(Color.<fcolor>);
  110. >040        <username>.setBackground(Color.<bcolor>);
  111. >048        popuppanel.addComponent(<>,"<>","<>");
  112.         
  113.         //
  114.         //  Add buttons to the bottom of the panel
  115.         //
  116.         if (moduleParameter.compareTo("Inquiry") == 0) {
  117. >041            <username>.setEditable(false);
  118.         } else {
  119. >042            <username>.setEditable(<editable>);
  120. >015            String buttons[] = {<"   Apply   ","Reset","New","Copy","Remove">};
  121. >047            int icons[] = {<>};
  122.             JDPButtons btns = new JDPButtons(user, buttons, icons, JDPButtons.HORIZONTAL);
  123.             centerMainPanel.add("South",btns);
  124. >046            popuppanel.addComponent(btns.button[<0>],"<>","<>");
  125.         }
  126.         mainPanel.add("Center",centerMainPanel);
  127.         
  128.         //
  129.         //  Define parameters for JDPWhereClause
  130.         //
  131. >016        String[] pchooseFrom = new String[<7>];
  132. >017        pchooseFrom[<0>] = "<Account Name>";
  133.  
  134. >018        String[] pactualchooseFrom = new String[<7>];
  135. >019        pactualchooseFrom[<0>] = "<username>";
  136.  
  137. >024        boolean[] constantIsString = new boolean[<7>];
  138. >025        constantIsString[<0>] = <true>;
  139.  
  140. >026        int[] constantLength = new int[<7>];
  141. >027        constantLength[<0>] = <20>;
  142.  
  143.         //
  144.         //  Add JDPWhereClause search panel
  145.         //
  146.         if (pchooseFrom.length > 0) {
  147. >028            jdpWhereClause = new JDPWhereClause(user, targetPanel, "<UserBill>", true, "<pinitChoice>", pchooseFrom, pactualchooseFrom,
  148.                                                 pmatchUsing, pactualmatchUsing, null, null,
  149.                                                 constantLength, constantIsString);
  150.             leftPanel.add("North",jdpWhereClause);
  151.         }
  152.         //
  153.         //  Add JDPSearchResults result list
  154.         //
  155.         if (psortChoice.length > 0) {
  156. >029            searchResults = new JDPSearchResults(user, targetPanel, <false>, jaggSQL, <false>, pselectFields, psdisplayFields, pfromWhereClause, psortChoiceText, psortChoice, pdisplayChoice, "<pinitChoice>", pdisplayCount, pcountText);
  157. >055            int icons[] = {<>};
  158. >056            searchResults.setMinWidth(<>);
  159.             searchResults.setIcons(icons);
  160.             leftPanel.add("Center",searchResults);
  161.             mainPanel.add("West",leftPanel);
  162.         }
  163.  
  164. >030        add("Center",new JDPChiselFramePanel(user,"<User Billing Details>",mainPanel,"North"));
  165.         if (psortChoice.length > 0) {
  166.             newSearch();
  167.         }
  168.         //
  169.         //  Add the handle to this panel to the global vector so other panels can
  170.         //  access this one
  171.         //
  172.         user.gParm.addElement(this);
  173.         clearFields();
  174.     }
  175.  
  176.     //
  177.     //  Handle screen events
  178.     //
  179.     public boolean handleEvent(Event e) {
  180.  
  181.         switch (e.id) {
  182.         case Event.ACTION_EVENT:
  183.             if (e.target instanceof List) {
  184.                 if (e.target.equals(searchResults.resultList)) {
  185.                     loadData();
  186.                     return true;
  187.                 }
  188.             }
  189.             if (e.target instanceof JDPTreePicker) {
  190.                 if (e.target.equals(searchResults.tree)) {
  191.                     loadData();
  192.                     return true;
  193.                 }
  194.             }
  195.             if (e.target instanceof Button) {
  196.                 String choice = (String)e.arg;
  197.                 if (choice.trim().compareTo("Apply") == 0) {
  198.                     if (checkFields()) {
  199.                         if (insertRequested) {
  200.                             saveData();
  201.                             newSearch();
  202.                         } else {
  203.                             saveData();
  204.                         }
  205.                     }
  206.                     return true;
  207.                 }
  208.                 if (choice.trim().compareTo("Reset") == 0) {
  209.                     loadData();
  210.                     return true;
  211.                 }
  212.                 if (choice.trim().compareTo("New") == 0) {
  213.                     insertRequested = true;
  214.                     clearFields();
  215.                     return true;
  216.                 }
  217.                 if (choice.trim().compareTo("Submit") == 0) {
  218.                     insertRequested = true;
  219.                     if (checkFields()) {
  220.                         saveData();
  221.                     }
  222.                     return true;
  223.                 }
  224.                 if (choice.trim().compareTo("Copy") == 0) {
  225.                     insertRequested = true;
  226.                     return true;
  227.                 }
  228.                 if (choice.trim().compareTo("Remove") == 0) {
  229. >054                    String removeMsg = "<>";
  230.                     if (removeMsg.equals("") || user.mainmsg.getStatusMsg().equals(removeMsg)) {
  231.                         insertRequested = false;
  232.                         deleteRequested = true;
  233.                         saveData();
  234.                         newSearch();
  235.                     } else {
  236.                         user.mainmsg.setStatusMsg(removeMsg,15);
  237.                     }
  238.                     return true;
  239.                 }
  240.                 if (choice.trim().compareTo("Search") == 0) {
  241.                     insertRequested = false;
  242.                     deleteRequested = false;
  243.                     newSearch();
  244.                     return true;
  245.                 }
  246.                 return true;
  247.             }
  248.             if (e.target instanceof Choice) {
  249.                 return true;
  250.             }
  251.             if (e.target instanceof TextField) {
  252.                 if ((jdpWhereClause != null) && (e.target.equals(jdpWhereClause.matchConstant))) {
  253.                     insertRequested = false;
  254.                     deleteRequested = false;
  255.                     newSearch();
  256.                     return true;
  257.                 }
  258.                 checkFields();
  259.                 return true;
  260.             }
  261.             return false;
  262.  
  263.         case Event.KEY_PRESS:
  264.             if (e.key == '\t') {
  265.                 //  handle tabbing between components
  266.                 if (e.modifiers != Event.SHIFT_MASK) {
  267. >031                    if (e.target.equals(<username>)) { user.u.cursor(<username>); return true; }
  268.                 } else {
  269. >038                    if (e.target.equals(<username>)) { user.u.cursor(<username>); return true; }
  270.                 }
  271.                 return true;
  272.             }
  273.             return false;
  274.  
  275.         case Event.WINDOW_EXPOSE:
  276.             if (e.target instanceof JDPTabSelectPanel) {
  277.                 if (e.target.equals(user.jdpMenuPanel)) {
  278.                     //
  279.                     //  This is where you place code to get executed when this panel is
  280.                     //  reactivated from the tab menu
  281.                     //
  282.                     return true;
  283.                 }
  284.             }
  285.             return false;
  286.  
  287.           case Event.MOUSE_MOVE:
  288.          case Event.MOUSE_ENTER:
  289.          case Event.MOUSE_EXIT:
  290.             popuppanel.postEvent(e);
  291.             return false;
  292.  
  293.         default:
  294.             return false;
  295.  
  296.         }
  297.     }
  298.  
  299.     //
  300.     //  Retrieve the handle to another panel so as to be able to interact with it
  301.     //
  302.     public void retrieveHandle() {
  303.  
  304.         for (int ix=0; ix<user.gParm.size(); ix++) {
  305.             //
  306.             //  Activate the next four lines of code to retrieve the handle to another 
  307.             //  Panel within your JDP system. Of course you should declare the variable 
  308.             //  at the top of this source instead of within this method so you can 
  309.             //  access it from all the methods within this class. You only need to 
  310.             //  substitute DemoClass with the name ouf your class. You should call this 
  311.             //  method from somewhere else in this class. To access a variable from 
  312.             //  your resulting class use:
  313.             //     if (DemoClassHandle != null) mynewvar = demoClassHandle.variable;
  314.             //
  315. //            if (user.gParm.elementAt(ix) instanceof DemoClass19) {
  316. //                DemoClass19 DemoClassHandle = (DemoClass19)user.gParm.elementAt(ix);
  317. //                return;
  318. //            }
  319.         }
  320.     }
  321.  
  322.     //
  323.     //  The search button was pressed so rerun the query with the new search criteria
  324.     //
  325.     public void newSearch() {
  326.  
  327.         String whereClause;
  328.  
  329.         whereClause = pfromWhereClause;
  330.         if (jdpWhereClause != null) {
  331.             whereClause = whereClause + " AND " + jdpWhereClause.whereClause;
  332.         }
  333.         searchResults.setFromWhereClause(whereClause);
  334. >057        searchResults.clearList(<>);
  335.         searchResults.loadList();
  336.     }
  337.  
  338.     //
  339.     //  Load the selected item
  340.     //
  341.     public void loadData() {
  342.  
  343.         StringTokenizer stok;
  344.  
  345.         int recCount = 0;
  346.         Vector results = new Vector();
  347.         String sep = jaggSQL.getSEP();
  348.         int actualRows = 0;
  349.         String row;
  350.         String tempText;
  351.  
  352.         if ((itemIndex = searchResults.getSelectedIndex()) < 0) {
  353.             clearFields();
  354.             return;
  355.         }
  356.  
  357. >032        String SQL = <SELECT username,firstname,lastname,status,cardnum,cardexpiry,cardname FROM JDPUser (NOLOCK) WHERE userid = " + thisuserid>;
  358.  
  359.         user.mainmsg.setStatusMsg("Accessing database...", 0);
  360.         recCount = jaggSQL.execSQL(SQL, results);
  361.  
  362.         if(recCount == -1) {
  363.             user.u.setSqlMessage(jaggSQL,SQL);
  364.             return;
  365.         }
  366.         if(recCount >= 1) {
  367.             row = (String)results.elementAt(0);
  368.             if ((row != null) && (row.trim().compareTo("") != 0)) {
  369.                 stok = new StringTokenizer(row);
  370.  
  371. >033                <username>.setText(stok.nextToken(sep).trim());
  372.             }
  373.             if(recCount > 1) {
  374.                 user.mainmsg.setStatusMsg("Multiple records found - first match only displayed.", 10);
  375.             } else {
  376.                 user.mainmsg.clearStatusMsg();
  377.             }
  378.         } else {
  379.             user.mainmsg.setStatusMsg("Requested entry does not exist.", 10);
  380.             clearFields();
  381.         }
  382.  
  383.     }
  384.  
  385.     //
  386.     //  Save the selected item
  387.     //
  388.     public boolean saveData() {
  389.  
  390.         int recCount = 0;
  391.         Vector results = new Vector();
  392.         String sep = jaggSQL.getSEP();
  393.         String SQL = "";
  394.  
  395.         if (insertRequested) {
  396. >034            SQL = <INSERT INTO >;
  397.         } else {
  398.             itemIndex = searchResults.getSelectedIndex();
  399.             if (itemIndex < 0) {
  400.                 user.mainmsg.setStatusMsg("You must first make a selection",5);
  401.                 return false;
  402.             }
  403.             if (deleteRequested) {
  404. >035                SQL = <DELETE FROM >;
  405.             } else {
  406. >036                SQL = <UPDATE >;
  407.             }
  408.         }
  409.  
  410.         user.mainmsg.setStatusMsg("Accessing database...", 0);
  411.         recCount = jaggSQL.execSQL(SQL, results);
  412.  
  413.         if(recCount == -1) {
  414.             user.u.setSqlMessage(jaggSQL,SQL);
  415.             return false;
  416.         }
  417.         if(recCount == 1) {
  418.             if (insertRequested) {
  419.                 user.mainmsg.setStatusMsg("Record successfully added.",3);
  420.             } else 
  421.             if (deleteRequested) {
  422.                 user.mainmsg.setStatusMsg("Record successfully removed.",3);
  423.             } else {
  424.                 user.mainmsg.setStatusMsg("Record successfully updated.",3);
  425.             }
  426.         } else {
  427.             user.u.setSqlMessage(jaggSQL,SQL);
  428.         }
  429.         insertRequested = false;
  430.         deleteRequested = false;
  431.         return true;
  432.  
  433.     }
  434.  
  435.     //
  436.     //  Clear the screen fields for a new option
  437.     //
  438.     public void clearFields() {
  439.  
  440. >037        <username>.setText("<>");
  441.  
  442.     }
  443.  
  444.     //
  445.     //  Load all of the Screen Choices
  446.     //
  447.     public void loadChoices() {
  448.  
  449.         pmatchUsing = new Vector();
  450.         pactualmatchUsing = new Vector();
  451. >020        pmatchUsing.addElement(new Vector());
  452. >022        pactualmatchUsing.addElement(new Vector());
  453. >021        ((Vector)pmatchUsing.elementAt(<0>)).addElement("<Begins with>");
  454. >023        ((Vector)pactualmatchUsing.elementAt(<0>)).addElement("< like >");
  455.  
  456. >043
  457. >044        new JDPLoadChoice(user,jaggSQL,<choicename>,"<choicecolumnname>","<actualcolumnname>","<tablename>","<whereclause>",value<columnname>);
  458.     }
  459.  
  460.     //
  461.     //  Perform component validations
  462.     //
  463.     public boolean checkFields() {
  464.  
  465. >045        if (!user.u.<isnumeric>(<field>,user.mainmsg,"<>")) return false;
  466.  
  467.         return true;
  468.  
  469.     }
  470.  
  471.  
  472. }
  473.